package com.heukyosuk.main;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.heukyosuk.socket.ClientThread;

public class IPActivity extends Activity {

	private EditText address, port;
	private ImageView connect;
	private String strIp;
	private int strPort;
	public static ClientThread ct;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_ip);

		address = (EditText) findViewById(R.id.editText_ip);
		port = (EditText) findViewById(R.id.editText_port);

		connect = (ImageView)findViewById(R.id.connect);
		connect.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				strIp = address.getText().toString();
				strPort = Integer.valueOf(port.getText().toString());
				
				ct = new ClientThread(strIp, strPort);
				
				Log.d("ip", strIp + " " + strPort);
				ct.execute();
				Log.d("ct", ct.connected +"");
				//if(ct.connected) {
					Intent intent = new Intent(IPActivity.this, MainActivity.class);
					startActivity(intent);
				//} else {
			//		Toast.makeText(getApplicationContext(), "you can't access the network", Toast.LENGTH_SHORT).show();	
					//finish();
			//	}
					
			}
		});
	}
}
